//
//  YSPTopView.swift
//  Weibo Demo
//
//  Created by 朴裕识 on 15/12/21.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit

class YSPTopView: UIView {
    
    var statusModel: YSPStatus? {
        didSet {
            //当cell的statusModel被赋值时，这里也开始根据status赋值控件
            setUIContent()
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
//        backgroundColor = UIColor.redColor()
        prepareUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setUIContent() {
        //1 iconView
        iconView.setImageWithURLString((statusModel?.userInfoArray?.profile_image_url)!)
        
        //2 nameLabel
        nameLabel.text = statusModel?.userInfoArray?.screen_name
        
        // 3 timeLabel
        timeLabel.text = "刚才"
        
        //4 sourceLabel
        sourceLabel.text = "遥远的艾泽拉斯"
        
        //5 vipView
        vipView.image = statusModel?.userInfoArray?.mbrankImage
        
        //6 verifiedView
        verifiedView.image = statusModel?.userInfoArray?.verifiedImage
    }
    
    private func prepareUI() {
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(vipView)
        addSubview(verifiedView)
        
        // 头像
        iconView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: 35, height: 35), offset: CGPoint(x: 8, y: 8))
        
        // 名称
        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
        
        // 时间
        timeLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
        
        // 来源
        sourceLabel.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: timeLabel, size: nil, offset: CGPoint(x: 8, y: 0))
        
        // 会员等级
        vipView.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: nameLabel, size: CGSize(width: 14, height: 14), offset: CGPoint(x: 8, y: 0))
        
        // 认证图标
        verifiedView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: CGSize(width: 17, height: 17), offset: CGPoint(x: 8.5, y: 8.5))

    }
    
    //MARK: - 懒加载
    ///头像
    private lazy var iconView = UIImageView(image: UIImage(named: "avatar"))
    
    ///昵称
    private lazy var nameLabel: UILabel = {
       let label = UILabel()
        // 设置字体颜色
        label.textColor = UIColor.darkGrayColor()
        // 设置大小
        label.font = UIFont.systemFontOfSize(14)
        label.text = "aaaaaaaaaaa"
        return label
    }()
    
    /// 微博时间
    private lazy var timeLabel: UILabel = {
        let label = UILabel()
        // 设置字体颜色
        label.textColor = UIColor.orangeColor()
        // 设置大小
        label.font = UIFont.systemFontOfSize(9)
        return label
    }()
    
    /// 微博来源
    private lazy var sourceLabel: UILabel = {
        let label = UILabel()
        
        // 设置字体颜色
        label.textColor = UIColor.lightGrayColor()
        
        // 设置大小
        label.font = UIFont.systemFontOfSize(9)
        
        return label
    }()
    
    /// 会员等级
    private lazy var vipView: UIImageView = UIImageView(image: nil)
    
    /// 认证图标
    private lazy var verifiedView: UIImageView = UIImageView(image: nil)
    
    
    
    
    

}
